
$('.close-btn').click(function(){
            $('.pay-list-box').hide();
        });


        $('#allPay').bind("click",function(){
            $(".yyxx-box").removeClass("hide");
            $('.pay-list-box').show();
            $('.pay-list-box').find("li").click(function(){
                if( ! $(this).hasClass('active')){
                    $(this).addClass('active').siblings().removeClass('active');
                }else{
                    $(this).removeClass('active');
                }
            });
            $('.close-btn').click(function(){
                StoreCache.removeCache("payInfo");
                $('.pay-list-box').hide();
            });


           var cfhms = "";
           var checkedBox = $("input.fwtc-choose-box:checked").parents(".bilsContent");
           if(checkedBox.length > 0){
            checkedBox.each(function () {
               cfhms += "," + $(this).find(".cfhm").html();
           });
               cfhms=cfhms.substr(1);

               $(".pay-btn").data("payInfo",{
                   cfhm:cfhms,
                   flje:"0.01"
               })
               $('.pay-list-box').show();
           }
        });
     function checkNum(value,i){
            var list = $("#noPayBill .bilsContent");
            var uncheck =  $(list[i]).find(".fwtc-choose-box")[0].uncheck;
            if(uncheck){
                 $.QuickAlert.alertNormal("不同的就诊号不能合并支付！");
                 $(list[i]).find(".fwtc-choose-box")[0].checked = false;
                 return false;
            }
            var jzh = value.jzlsh;
            var checked = $(list[i]).find("input")[0].checked;
            var checkedBox = $("input.fwtc-choose-box:checked").parents(".bilsContent");
            if(checkedBox.length>1){
                return;
            }else if(checkedBox.length ==1){
                 $(list).each(function(index,arr){
                    if(index !=i && value.jzlsh!=jzh ){
                        var input =  $(list[index]).find(".fwtc-choose-box")[0];
                            input.uncheck = true;
                    }else{
                          var input =  $(list[index]).find(".fwtc-choose-box")[0];
                            input.disabled = false;
                    }
                })
            }else{
                $(list).each(function(index,arr){
                        var input =  $(list[index]).find(".fwtc-choose-box")[0];
                            input.uncheck = false;
                })
            }
           
        }
    $(function () {
        $('.pay-list-box').find("li").click(function(){
            if( ! $(this).hasClass('active')){
                $(this).addClass('active').siblings().removeClass('active');
            }else{
                $(this).removeClass('active');
            }
        })
        /**医院信息table切换*/
        $("#ListTab").on("click", "li", function () {
            if (!$(this).hasClass("active")) {
                $(this).addClass("active").siblings().removeClass("active");
            }
            var index = $(this).attr("index");
            $("#ListTabBox").find(".tab").hide();
            $("#ListTabBox").find(".tab[index='" + index + "']").show();
        });

        /**获取跳转路径参数判断tab切换*/
        var tab = $.QuickUrlUtils.getRequest("HOSDETAIL_TAB");
        if (!StringUtils.isEmpty(tab)) {
            $("#ListTab").find("li[index='" + tab + "']").trigger("click");
        }
    // initNoPayData();
    //动态获取数据
     var searchInfo =  StoreCache.getCache("searchInfo");
     var getPrescriptionRecordParam = {
        yljgdm:searchInfo.hosCode,
        klx:"01",
        kh:searchInfo.patientCardId,
        zzmzsj:searchInfo.beginTime,
        zwmzsj:searchInfo.endTime,
        jzlsh:""};
    // var getPrescriptionRecordParam = {
    //     yljgdm:"740035778",
    //     klx:"01",
    //     kh:"510123199101273421",
    //     zzmzsj:"2017-01-01",
    //     zwmzsj:"2017-12-31",jzlsh:"201711150002"};
    $.QuickRemote.AjaxJson({
        funcName:"/api/gzd/ynzf/report/getPendingPaymentInfo"
        ,callback:initNoPayData
        ,params:getPrescriptionRecordParam
    });
    function initNoPayData(arr) {
        if(arr && arr.length>0){
                
            var str = template("noPayBillTpl", {data:arr});
           $('#noPayBill').append(str);
           var str1 = template("allPayTpl", {data:arr});
            $('#allBill').append(str1);
        
           
        }
        
    }
    // payed();
    //动态获取数据
    var searchInfo =  StoreCache.getCache("searchInfo");
        var getPrescriptionRecordParam = {
            yljgdm:searchInfo.hosCode,
            klx:"01",
            kh:searchInfo.patientCardId,
            ksrq:searchInfo.beginTime,
            jsrq:searchInfo.endTime
        };
        // var getPrescriptionRecordParam = {
        //     yljgdm:"451135959",
        //     klx:"01",
        //     kh:"510123199101273421",
        //     ksrq:"2017-01-01",
        //     jsrq:"2018-03-20"
        // };
         $.QuickRemote.AjaxJson({
            funcName:"/api/gzd/ynzf/report/findCompletePayRecord"
            ,callback:payed
            ,params:getPrescriptionRecordParam
        }); 
    function payed(arr) {
        if(arr && arr.length>0){

            var str = template("paiedTpl", {data:arr});
             $('#allBill').append(str);
             $('#paied').append(str);
           
        }
        
    }
 $(".pay-btn").on("click",function(){
            var jq = $("#payMode").find(".active[value]");
            var length = $(jq).length;
            if(length == 0){
                $.QuickAlert.alertFail({
                    content : "请选择支付方式！"
                });
            }else{
                $(".yyxx-box").addClass("hide");
                $('.pay-list-box').hide();
                toPay();
            }
        });
});
    function displayDrug(index){
        var userinfo = StoreCache.getCache("selecteUser");

        var hosCode= $.QuickUrlUtils.getRequest("hosId");
       var loadState = $("#DrugList"+index).attr("loadState") || "standby";
       if(loadState != "loaded"){
         $.QuickRemote.AjaxJson("/api/jkcsHt/ynzf/report/getPrescriptionDetail",function(result){
             $("#DrugList"+index).attr("loadState","loaded");
            var tr = template("cfDetailTpl", {data:result});
            $("#DrugList" + index).find("table").find("tbody").append(tr);

         },{
             yljgdm:hosCode,
            kh:"510123199101273421",
            klx:"01",
            cfhm:$("#display" + index).attr("value"),
             jzlsh:""
         });
       }
        if($("#DrugList"+index) && $("#DrugList"+index).hasClass('hide')){
            $("#DrugList"+index).removeClass("hide");
             $("#display"+index)[0].innerHTML = "收起";
        }else{
             $("#DrugList"+index).addClass("hide");
             $("#display"+index)[0].innerHTML = "查看详情";
        }

    }
     $.JkcsUtils.jsbridgeRegister("payEnd", function(params){
           //console.log(params);
            payEnd(params);
        });
          $.JkcsUtils.jsbridgeRegister("visibleRefresh", function(params){
           //console.log(params);
            visibleRefresh(params);
        });
    function toOpenPay(data){
          $('.pay-list-box').show();
          $(".pay-btn").data("payInfo",data);
    }
   function toPay(){
    var searchInfo =  StoreCache.getCache("searchInfo");
    var data =$(".pay-btn").data("payInfo");
       $.QuickRemote.AjaxJson({
            funcName:"/api/gzd/ynzf/report/getZjzfOrderId"
            ,callback:function (info) {
                var orderId = info.orderId;
                var orgInfo = info.appInfo;
                var obj = {
                    appid:orgInfo.appid,
                    appSecret:orgInfo.workKey,
                    submerno:info.submerno,
                    channelType:'alipay',
                    goods_desc:'诊间付费',
                    billNum:orderId,
                    order_desc:'处方付费',
                    billTotalFee:1,
                    billTitle:"处方付费"
                };
                $.JkcsUtils.nativePermission({
                    "type": "pay",
                    "callBackMethod": "payEnd",
                    "params":obj
                });
       }
       ,params:{
           yljgdm:searchInfo.hosCode,
           klx:"01",
           kh:searchInfo.patientCardId,
           je:"0.01",//data.flje,
           cfhms:data.cfhm
       }});



        // var obj={
        //     appid:'305101700000170',
        //     appSecret:sign,
        //     submerno:'305101700000170',
        //     channelType:'alipay',
        //     goods_desc:'测试商品',
        //     billNum:"8977672323hbsd4",
        //     order_desc:'just a test',
        //     billTotalFee:1,
        //     billTitle:"娃哈哈"
        // }


   }
   function visibleRefresh(data){
        // alert("1")
   }
    function payEnd(data){
        var msg ="";
        if(data.payStateCode==-1){
                msg ="取消支付";
        }else if(data.payStateCode==0){
             msg ="支付失败";
        }else if(data.payStateCode==1){
            msg="支付成功";
        }
        $.QuickAlert.alertNormal(msg);
   }
 
